package com.yanqu.road.server.logic.activity.stronghold;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.UserActivityConditionData;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.logic.activity.orewar.condition.BaseOreWarActivityCondition;
import com.yanqu.road.server.logic.activity.stronghold.condition.BaseStrongholdActivityCondition;
import com.yanqu.road.server.manger.activity.ActivityMgr;

import java.util.ArrayList;
import java.util.List;

public class StrongholdActivityData {

    private GamePlayer player;

    private ActivityInfo activityInfo;

    private List<UserActivityConditionData> userActivityConditionDataList;

    private List<BaseStrongholdActivityCondition> baseActivityConditionList;

    public StrongholdActivityData(GamePlayer player, ActivityInfo activityInfo, List<UserActivityConditionData> userActivityConditionDataList) {
        this.player = player;
        this.activityInfo = activityInfo;
        this.userActivityConditionDataList = userActivityConditionDataList;
        baseActivityConditionList = new ArrayList<>();
    }

    public List<UserActivityConditionData> getUserActivityConditionDataList() {
        return userActivityConditionDataList;
    }

    public boolean isInTime() {
        return ActivityMgr.activityInTime(activityInfo);
    }
    public boolean isInTime20Min() {
        return ActivityMgr.activityInTime20Min(activityInfo);
    }

    public boolean isShowTime() {
        return ActivityMgr.activityInShowTime(activityInfo);
    }

    public void addUserActivityConditionData(UserActivityConditionData userConditionData) {
        userActivityConditionDataList.add(userConditionData);
    }

    public void addCondition(BaseStrongholdActivityCondition condition) {
        if (baseActivityConditionList == null) {
            baseActivityConditionList = new ArrayList<>();
        }
        baseActivityConditionList.add(condition);
    }

    public void addToPlayer() {
        for (BaseStrongholdActivityCondition baseActivityCondition : baseActivityConditionList) {
            baseActivityCondition.addTrigger(player);
        }
    }

    public void finish(int conditionId) {
        for (BaseStrongholdActivityCondition baseActivityCondition : baseActivityConditionList) {
            if (baseActivityCondition.getConditionId() == conditionId) {
                baseActivityCondition.removeTrigger(player);
            }
        }
    }

    public int getActivityId() {
        return activityInfo.getActivityId();
    }

    public GamePlayer getPlayer() {
        return player;
    }

    public boolean continueAdd(int type) {
        for (BaseStrongholdActivityCondition condition : baseActivityConditionList) {
            int conditionType = condition.getConditionType();
            if (conditionType == type) {
                return false;
            }
        }
        return true;
    }

    public UserActivityConditionData getUserActivityConditionData(int conditionId) {
        for (UserActivityConditionData conditionData : userActivityConditionDataList) {
            if (conditionData.getConditionId() == conditionId) {
                return conditionData;
            }
        }
        return null;
    }

    public BaseStrongholdActivityCondition getActivityCondition(int conditionId) {
        for (BaseStrongholdActivityCondition activityCondition : baseActivityConditionList) {
            if (activityCondition.getConditionId() == conditionId) {
                return activityCondition;
            }
        }
        return null;
    }

    public UserActivityConditionData getFirstConditionData() {
        return userActivityConditionDataList.get(0);
    }

    public List<BaseStrongholdActivityCondition> getBaseActivityConditionList() {
        return baseActivityConditionList;
    }
}
